package dao;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.exception.JDBCConnectionException;

import dominio.Logs;
import excepciones.DAOExcepcion;

public class DaoLogs {
		
	private static Session sesion = null; // Hibernate Session
	private static Transaction tx = null; // Hibernate Transaction
	
	public DaoLogs() {
		
	}

	public void anadirLog(Logs log) throws DAOExcepcion {
		try {
			sesion = UtilidadHibernate.getSessionFactory().openSession();
			tx = sesion.beginTransaction();
			sesion.save(log);
			tx.commit();
		} 
		catch (JDBCConnectionException e){  // no puede conectar con la bd, error grave.
			System.out.println("Error al conectar con la base de datos " + e + "\n");
		}
		catch (HibernateException e) {
			tx.rollback();
			throw new DAOExcepcion(e);
		} 
		return;
	}

}
